// function ModelCreator(Model) {
//   class ModelExtend extends Model {
//     constructor(...args) {
//       super(...args)
//     }
//   }

// static async onchange(...args) {
//   const [ids, values, field_name, field_onchange, kwargs = {}] = args
//   const res = super.onchange(...args)

//   if (field_name === 'order_line') {
//     const { value: valueold } = res
//     const value = { ...valueold }
//     delete value.order_line
//     return { ...res, value }
//   } else {
//     return res
//   }
// }

//   return ModelExtend
// }

const metadata = {
  // state: {
  //   selection: [
  //     ['draft', 'Quotation'],
  //     ['sent', 'Quotation Sent'],
  //     ['sale', 'Sales Order'],
  //     ['done', 'Locked'],
  //     ['cancel', 'Cancelled']
  //   ]
  // },

  user_id: {
    // domain=lambda self: "[('groups_id', '=', {}), ('share', '=', False), ('company_ids', '=', company_id)]".format(self.env.ref("sales_team.group_sale_salesman").id

    domain: [
      ['share', '=', false],
      ['company_ids', '=', { field_company_id: {} }]
    ],

    async async_domain({ env }) {
      const refid = await env.ref('sales_team.group_sale_salesman').id
      return ({ record }) => {
        // domain=lambda self: "
        // [('groups_id', '=', {}), ('share', '=', False),
        // ('company_ids', '=', company_id)]".format(
        //  self.env.ref("sales_team.group_sale_salesman").id
        const { company_id } = record
        return [
          ['groups_id', '=', refid],
          ['share', '=', false],
          ['company_ids', '=', company_id]
        ]
      }
    }
  }
}

const AddonsModels = {
  'sale.order': {
    // ModelCreator,
    metadata
  }
}

export default AddonsModels
